<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2016-6-21
 * Func   通知
 */
defined('IN_YuLin') || exit('NO PERMIT!');

$table = Table('agent_notice');

if($a == 'view')
{
    $id = intval($_GET['id']);
    $data = $id ? $db->getrow('SELECT * FROM '.$table.' WHERE id = '.$id.' AND status = 1') : [];

    $tpl->display($m.'/notice_view');
}
else
{
    $data  = [];
    $where = ' FROM '.$table.' t WHERE status = 1 ';
	
	$cid = intval($_GET['cid']);
	$cid && $where .= ' AND cid = '.$cid;
	
	$title = NoBadStr($_GET['title']);
	$title && $where .= ' AND title LIKE \'%'.$title.'%\'';
	
    $tmp = $db->getrow('SELECT COUNT(1) AS p '.$where);
    if($tmp['p'])
	{
        $page = max(1,intval($_GET['page']));
        $size = 20;
        $limit    = ' LIMIT '.($page - 1) * $size.','.$size;

		$url = '?m='.$m.'&c='.$c.'&title='.$title.'&cid='.$cid;
        $orderby = ' ORDER BY t.id DESC ';
		
        $data = $db->getall('SELECT t.* '.$where.$orderby.$limit);
		
        $multi = Multi($url,$page,$tmp['p'],$size);
    }

    $tpl->display($m.'/notice');
}